<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Clases que voy a usar **/
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Config');
Zend_Loader::loadClass('Zend_Config_Ini');
Zend_Loader::loadClass('Zend_Db');
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Registry');
Zend_Loader::loadClass('Zend_Acl');
Zend_Loader::loadClass('Zend_Auth');
Zend_Loader::loadClass('Zend_Session');

/** Base de Datos **/
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/db_config.ini', 'desarrollo');
$dbAdapter = Zend_Db::factory($config->database->adapter,
                       $config->database->params->toArray());
Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
Zend_Registry::set('dbAdapter', $dbAdapter);
$dbName = $config->database->params->dbname;
Zend_Registry::set('dbName', $dbName);

/** Upload **/
$upload_paths = new Zend_Config_Ini(APPLICATION_PATH . '/configs/upload.ini', 'desarrollo');
Zend_Registry::set('upload_paths', $upload_paths);

/** Permisos **/
require_once APPLICATION_PATH . '/permisos/Acl.php';
$acl = new Application_Permiso_Acl();
Zend_Registry::set('acl',$acl);

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();
